import java.util.*;

public class StockSpanner {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public StockSpanner() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }
    public int next(int price) {
        if (stack1.isEmpty()) {
            stack1.push(price);
            return 1;
        }
        int count = 0;
        while (price >= stack1.peek()) {
            int top = stack1.pop();
            stack2.push(top);
            count++;
        }
        while (!stack2.isEmpty()) {
            int top = stack2.pop();
            stack1.push(top);
        }
        stack1.push(price );
        return 1+count;
    }
}
